<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>gozerlib.persist.persiststate &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../../index.html" />
    <link rel="next" title="gozerlib.plugs.admin" href="../plugs/admin.html" />
    <link rel="prev" title="gozerlib.persist.persist" href="persist.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="../plugs/admin.html" title="gozerlib.plugs.admin"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="persist.html" title="gozerlib.persist.persist"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-gozerlib.persist.persiststate">
<h1>gozerlib.persist.persiststate<a class="headerlink" href="#module-gozerlib.persist.persiststate" title="Permalink to this headline">¶</a></h1>
<p>persistent state classes.</p>
<dl class="class">
<dt id="gozerlib.persist.persiststate.ObjectState">
<em class="property">class </em><tt class="descclassname">gozerlib.persist.persiststate.</tt><tt class="descname">ObjectState</tt><a class="headerlink" href="#gozerlib.persist.persiststate.ObjectState" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="gozerlib.persist.persiststate.PersistState" class="reference internal" href="#gozerlib.persist.persiststate.PersistState"><tt class="xref docutils literal"><span class="pre">gozerlib.persist.persiststate.PersistState</span></tt></a></p>
<p>state for usage in constructors.</p>
</dd></dl>

<dl class="class">
<dt id="gozerlib.persist.persiststate.PersistState">
<em class="property">class </em><tt class="descclassname">gozerlib.persist.persiststate.</tt><tt class="descname">PersistState</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#gozerlib.persist.persiststate.PersistState" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="gozerlib.persist.persist.Persist" class="reference external" href="persist.html#gozerlib.persist.persist.Persist"><tt class="xref docutils literal"><span class="pre">gozerlib.persist.persist.Persist</span></tt></a></p>
<p>base persitent state class.</p>
<dl class="method">
<dt id="gozerlib.persist.persiststate.PersistState.define">
<tt class="descname">define</tt><big>(</big><em>key</em>, <em>value</em><big>)</big><a class="headerlink" href="#gozerlib.persist.persiststate.PersistState.define" title="Permalink to this definition">¶</a></dt>
<dd>define a state item.</dd></dl>

</dd></dl>

<dl class="class">
<dt id="gozerlib.persist.persiststate.PlugState">
<em class="property">class </em><tt class="descclassname">gozerlib.persist.persiststate.</tt><tt class="descname">PlugState</tt><a class="headerlink" href="#gozerlib.persist.persiststate.PlugState" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="gozerlib.persist.persiststate.PersistState" class="reference internal" href="#gozerlib.persist.persiststate.PersistState"><tt class="xref docutils literal"><span class="pre">gozerlib.persist.persiststate.PersistState</span></tt></a></p>
<p>state for plugins.</p>
</dd></dl>

<dl class="class">
<dt id="gozerlib.persist.persiststate.UserState">
<em class="property">class </em><tt class="descclassname">gozerlib.persist.persiststate.</tt><tt class="descname">UserState</tt><big>(</big><em>username</em><big>)</big><a class="headerlink" href="#gozerlib.persist.persiststate.UserState" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="gozerlib.persist.persiststate.PersistState" class="reference internal" href="#gozerlib.persist.persiststate.PersistState"><tt class="xref docutils literal"><span class="pre">gozerlib.persist.persiststate.PersistState</span></tt></a></p>
<p>state for users.</p>
</dd></dl>

<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74</pre></td><td class="code"><div class="highlight"><pre><span class="c"># gozerlib/persist/persiststate.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; persistent state classes. &quot;&quot;&quot;</span>

<span class="c">## gozerlib imports</span>

<span class="kn">from</span> <span class="nn">gozerlib.utils.trace</span> <span class="kn">import</span> <span class="n">calledfrom</span>
<span class="kn">from</span> <span class="nn">persist</span> <span class="kn">import</span> <span class="n">Persist</span>

<span class="c">## basic imports</span>

<span class="kn">import</span> <span class="nn">types</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>

<span class="k">class</span> <span class="nc">PersistState</span><span class="p">(</span><span class="n">Persist</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; base persitent state class. &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="n">Persist</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="p">{})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">types</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">((</span><span class="n">i</span><span class="p">,</span> <span class="nb">type</span><span class="p">(</span><span class="n">j</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">iteritems</span><span class="p">())</span>

    <span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; get state item. &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">__setitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; set state item. &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

    <span class="k">def</span> <span class="nf">define</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; define a state item. &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">type</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">key</span><span class="p">]:</span>

            <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="o">==</span> <span class="n">types</span><span class="o">.</span><span class="n">StringType</span><span class="p">:</span>
                <span class="n">value</span> <span class="o">=</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>

            <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="o">==</span> <span class="n">types</span><span class="o">.</span><span class="n">IntType</span><span class="p">:</span>
                <span class="n">value</span> <span class="o">=</span> <span class="nb">long</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

<span class="k">class</span> <span class="nc">PlugState</span><span class="p">(</span><span class="n">PersistState</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; state for plugins. &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plugname</span> <span class="o">=</span> <span class="n">calledfrom</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">_getframe</span><span class="p">())</span>
        <span class="n">rlog</span><span class="p">(</span><span class="mf">1</span><span class="p">,</span> <span class="s">&#39;persiststate&#39;</span><span class="p">,</span> <span class="s">&#39;initialising </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">plugname</span><span class="p">)</span>
        <span class="n">PersistState</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&#39;gozerstore&#39;</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="s">&#39;plugs&#39;</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">plugname</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="s">&#39;state&#39;</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">ObjectState</span><span class="p">(</span><span class="n">PersistState</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; state for usage in constructors. &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">PersistState</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&#39;gozerstore&#39;</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="n">calledfrom</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">_getframe</span><span class="p">(</span><span class="mf">1</span><span class="p">))</span><span class="o">+</span><span class="s">&#39;.state&#39;</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">UserState</span><span class="p">(</span><span class="n">PersistState</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; state for users. &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">username</span><span class="p">):</span>
        <span class="n">datadir</span> <span class="o">=</span> <span class="s">&#39;gozerstore&#39;</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="s">&#39;users&#39;</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="n">username</span>
        <span class="n">PersistState</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>  <span class="n">datadir</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">sep</span> <span class="o">+</span> <span class="s">&#39;state&#39;</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">gozerlib.persist.persiststate</a><ul>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="persist.html"
                                  title="previous chapter">gozerlib.persist.persist</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="../plugs/admin.html"
                                  title="next chapter">gozerlib.plugs.admin</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../../_sources/gozerlib/persist/persiststate.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../plugs/admin.html" title="gozerlib.plugs.admin"
             >next</a> |</li>
        <li class="right" >
          <a href="persist.html" title="gozerlib.persist.persist"
             >previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>